package assg.funnycells.util;

public class StringOperations {
    
    public static String parseContext(String readline) {
	if(readline.startsWith("[") && readline.endsWith("]"))
	    return readline.substring(1, readline.length() - 1).trim();
	else
	    return "";
    }

    public static String parseKey(String readline) {
	int index = readline.indexOf("=");
	if(index != -1)
	    return readline.substring(0, index).trim();
	else
	    return "";
    }

    public static String parseVal(String readline) {
	int index = readline.indexOf("=");
	if(index != -1)
	    return readline.substring(index + 1).trim();
	else
	    return "";
    }

    public static int parseInt(String readline) {
	try {
	    return Integer.parseInt(readline);
	} catch(Exception e) {
	    return -1;
	}
    }

    public static boolean parseBoolean(String readline) {
	try {
	    return Boolean.parseBoolean(readline);
	} catch(Exception e) {
	    return false;
	}
    }

    public static long parseLong(String readline) {
	try {
	    return Long.parseLong(readline);
	} catch(Exception e) {
	    return -1;
	}
    }
}